package com.kdzy.lshy.socity_server.common;

import sun.misc.BASE64Encoder;

import java.io.File;
import java.io.FileInputStream;

/**
 * 文件工具类
 * @author cly
 * @since 2018-06-21
 */
public class FileUtils {

    /**
     * 将图片转换成base64编码格式
     * @param filePath 文件路径
     * @return 结果集
     */
    public static String encryptToBase64(String filePath) {

        File file = new File(filePath);
        FileInputStream inputFile = null;

        try {
            inputFile = new FileInputStream(file);
            byte[] buffer = new byte[(int) file.length()];
            inputFile.read(buffer);
            inputFile.close();
            return new BASE64Encoder().encode(buffer);
        } catch (Exception e) {
            e.printStackTrace();
            return "fail";
        }

    }
}
